const PRODUCT = process.env.NODE_ENV == "production";
let headers = {
  "Content-Type": "application/json",
  "X-Requested-With": "XMLHttpRequest"
};

if (process.env.NODE_ENV == "development") {
  //开发环境,请求头设置参数
  headers = Object.assign({}, headers, {
    wecSchoolId: 1019427682571829,
    wecUserInfo: JSON.stringify({
      userAccount: "123123",
      userName: "admin1",
      userId: "72786"
    })
  });
}

const axiosConfig = {
  baseURL: PRODUCT ? "/" : "/",
  headers: headers,
  // 请求后的数据处理
  transformResponse: [
    function(data) {
      const response = typeof data === "object" ? data : JSON.parse(data);
      return response;
      //return data; 修改处理之后的模式
    }
  ],
  transformRequest: [
    function(data = {}) {
      return JSON.stringify(data);
    }
  ],
  // 超时设置s
  timeout: 30000,
  // 跨域是否带Token
  withCredentials: false,
  responseType: "json",
  // xsrf 设置
  xsrfCookieName: "XSRF-TOKEN",
  xsrfHeaderName: "X-XSRF-TOKEN",
  // 最多转发数，用于node.js
  maxRedirects: 5,
  // 最大响应数据大小
  maxContentLength: 2000
};
export default axiosConfig;
